package com.w7vm.menuweb.facade;

import javax.ejb.Remote;
import javax.ejb.Stateless;
import javax.naming.InitialContext;
import javax.naming.NamingException;

import com.w7vm.componente.facade.CorreioFacadeRemote;
import com.w7vm.componente.ws.Webservicecep;

@Stateless
@Remote(CorreioFacade.class)

public class CorreioFacadeImp implements CorreioFacade{

	
	@Override
	public Webservicecep getEndereco(String cep) {
		try{
			System.out.println("Try access remote method in CorreioEJB");
			
			InitialContext ctx = new InitialContext();
			CorreioFacadeRemote enderecoEJB = (CorreioFacadeRemote) ctx.lookup
					("java:global/CorreioEJB/CorreioFacadeBean!com.w7vm.componente.facade.CorreioFacadeRemote");

			System.out.println("Object Remote "+ enderecoEJB);

			Webservicecep endEJB = enderecoEJB.getEndereco(cep);

			System.out.println("Object Remote Return Method "+ endEJB);

			return endEJB;
			
		} catch (NamingException ex){
			ex.printStackTrace();
			System.out.print("Não acesso CorreioEJB");
		}catch (Exception ex){
			ex.printStackTrace();
			System.out.print(ex.getMessage());
		}
		return null;
	}
	
}
